package com.atguigu.lease.common.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author cxt
 * &#064;Description 自定义redis模板(key是String,Value是Object)
 * &#064;create 2025/3/22 下午3:37
 */
@Configuration
public class RedisConfiguration {
    @Bean
    public RedisTemplate<String, Object> RedisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
//      设置key模板是String类型
        template.setKeySerializer(RedisSerializer.string());
//      设置Value模板是Object类型
        template.setValueSerializer(RedisSerializer.java());
        return template;
    }
}
